***********************
*Replication code for Claassen, Djupe, Lewis, and Neiheisel. "Which Party Represents My Group? The Group Foundations of Partisan Choice and Polarization."
*Forthcoming at Political Behavior.

*File contains code for the three datasets used in the paper.
*November 2015 (SSI) n=1,517 - "november2015.dta"
*March 2016 (SSI) n= 1,000 - "march2016.dta"
*June 2017 (Qualtrics) n=1,137 - "june2017.dta"


*Just for checking purposes:
cd "C:\Users\pdjup\Dropbox\Party Perceptions\Data files for dataverse\"

************************
*All recodes and analyses using the November 2015 data.
************************

use november2015.dta

*Recodes
gen female=sex-1 // men=0, women=1

*Partisanship
recode pid7 (1/3=0)(4=1)(5/7=2), gen(pid3) // 0=dem, 1=ind, 2=rep

*Religious nones
recode relig (-99/11=0)(12 13 15=1)(14=0), gen(none)


*Born again
recode born_again (4/5=1)(1/3=0)(.=0), gen(ba) // only asked of Christians
replace ba=0 if relig==1 // drop catholics into 0
replace ba=0 if white==0 // drop non-whites into 0


*Difference between Rep and Democratic therms
gen drdiff=therm_rep-therm_dem


*Figure 2 – Beliefs about the Percent of Nones in the Democratic Party and Evangelicals in the Republican Party by Subgroups (November 2015 Data)
sum dem_attend rep_evang // sample perception
sum dem_attend if none==1 // among nones
sum rep_evang if none==1 // among nones
sum dem_attend if none==1 & pid3==0 // among Dem nones
sum rep_evang if none==1 & pid3==0 // among Dem nones
sum dem_attend if none==1 & pid3==2 // among Rep nones
sum rep_evang if none==1 & pid3==2 // among Rep nones
sum dem_attend if ba==1 //among evans
sum rep_evang if ba==1 // among evans
sum dem_attend if ba==1 & pid3==0 // among Dem evans
sum rep_evang if ba==1 & pid3==0 // among Dem evans
sum dem_attend if ba==1 & pid3==2 // among Rep evans
sum rep_evang  if ba==1 & pid3==2 // among Rep evans
sum none if pid3==0  // party proportion
sum ba if pid3==2 // party proportion

*Table A0 – Descriptive Statistics from the Three Samples
summ female white age ba none  
tab1 educ pid3 

*Table A1 – Slope Coefficients and R2 for how Beliefs about Republican Evangelical Proportions are Linked to Beliefs about Democratic None Proportions Across the Three Surveys
reg dem_attend rep_evang if none==1
reg dem_attend rep_evang if none==0

*Table A2 - How Beliefs about the Religious Composition of the Parties are Linked to Partisanship – November 2015 Data
reg drdiff i.none##c.dem_attend i.none##c.rep_evang i.ba##c.dem_attend i.ba##c.rep_evang female white age educ attend
reg pid7 i.none##c.dem_attend i.none##c.rep_evang i.ba##c.dem_attend i.ba##c.rep_evang female white age educ attend


*Figure 3 – The Interactive Effects of Religious Group Membership and Perceptions of Party Composition on Partisanship
*First column of results
reg pid7 i.none##c.dem_attend i.none##c.rep_evang i.ba##c.dem_attend i.ba##c.rep_evang female white age educ attend 

margins, at(dem_attend=(0(10)100) none=(0 1)) l(76)
marginsplot, graphregion(color(white)) xtitle("Democratic Non-Attenders") recastci(rspike) ciopt(lc(gs10)) ///
		plot1op(lc(black) mc(black) ms(O)) plot2op(lc(black) mc(black) ms(Sh)) ytitle("Partisanship") ///
		addplot(hist dem_attend, percent yaxis(2) yscale(ax(2) range(0 100) alt off) fc(gs12) legend(order(3 "Religious" 4 "Nones") region(color(white)))) ///
		title("November 2015") name(dem_nonep15, replace)
margins, at(rep_evang=(0(10)100) ba=(0 1)) l(76)
marginsplot, graphregion(color(white)) xtitle("Republican Evangelicals") recastci(rspike) ciopt(lc(gs10)) ///
		plot1op(lc(black) mc(black) ms(O)) plot2op(lc(black) mc(black) ms(Sh)) ytitle("Partisanship") ///
		addplot(hist rep_evang, percent yaxis(2) yscale(ax(2) range(0 100) alt off) fc(gs12) legend(order(3 "Other" 4 "Evangelicals") region(color(white)))) ///
		title("")  name(rep_evanp15, replace) title("November 2015")

graph combine dem_nonep15 rep_evanp15, col(1) graphregion(color(white))



*Figure 4 – The Interactive Effects of Religious Group Membership and Perceptions of Party Composition on Partisan Feelings (November 2015 and June 2017)
*First column of results
reg drdiff i.none##c.dem_attend i.none##c.rep_evang i.ba##c.dem_attend i.ba##c.rep_evang female white age educ attend
	*outreg2 using andyresults.doc, dec(2)
margins, at(dem_attend=(0(10)100) none=(0 1)) l(76)
marginsplot, graphregion(color(white)) xtitle("Democratic Non-Attenders") recastci(rspike) ciopt(lc(gs10)) ///
		plot1op(lc(black) mc(black) ms(O)) plot2op(lc(black) mc(black) ms(Sh)) ytitle("Republican-Democratic FT") ///
		addplot(hist dem_attend, percent yaxis(2) yscale(ax(2) range(0 100) alt off) fc(gs12) legend(order(3 "Religious" 4 "Nones") region(color(white)))) ///
		title("November 2015") name(dem_none15, replace)
margins, at(rep_evang=(0(10)100) ba=(0 1)) l(76)
marginsplot, graphregion(color(white)) xtitle("Republican Evangelicals") recastci(rspike) ciopt(lc(gs10)) ///
		plot1op(lc(black) mc(black) ms(O)) plot2op(lc(black) mc(black) ms(Sh)) ytitle("Republican-Democratic FT") ///
		addplot(hist rep_evang, percent yaxis(2) yscale(ax(2) range(0 100) alt off) fc(gs12) legend(order(3 "Other" 4 "Evangelicals") region(color(white)))) ///
		title("November 2015")  name(rep_evan15, replace)
graph combine dem_none15 rep_evan15, col(1) graphregion(color(white))


************************
*All recodes and analyses using the March 2016 data.
************************
use march2016.dta

*Recodes

*Evangelical
gen evan=0
replace evan=ri_1 if ri_1==1 // "evangelical"
replace evan=ri_2 if ri_2==1 // "fundamentalist"
replace evan=ri_4 if ri_4==1 // "born again"
replace evan=ri_6 if ri_6==1 & relid<4 // "conservative" and christian
replace evan=0 if white!=1

*Nones
recode relid (7 8=1)(1/6=0), gen(none) // none, atheist, agnostic=1

*Figure 1 – How Beliefs about the Evangelical Percent of Republicans and Religious None Percent of Democrats are Distributed and Linked (March 2016 Data) 
*This was made in R, but this syntax is equivalent.
twoway scatter q43_2 q42_4 || qfitci q43_2 q42_4, xtitle("Perceived Percent None Democrats") ///
	ytitle("Perceived Percent Evangelical Republicans") graphregion(color(white))

*Table A0 – Descriptive Statistics from the Three Samples
summ female white age evan none
tab1 ed pid3

*Figure A1 – Distribution of Beliefs about the Religious Composition of the Parties by Nones and Religious Americans (March 2016 Data)
*This was made in R, but this is equivalent code
twoway lowess q43_2 q42_4  if none==1, title("None") ///
	|| scatter q43_2 q42_4  if none==1, name(None, replace)	xtitle("Perceived Percent None Democrats") ///
	ytitle("Perceived Percent Evangelical Republicans") graphregion(color(white)) 
twoway lowess q43_2 q42_4  if none==0, title("Religious") ///
	|| scatter q43_2 q42_4  if none==0, name(Religious, replace) xtitle("Perceived Percent None Democrats") ///
	ytitle("Perceived Percent Evangelical Republicans") graphregion(color(white)) 
graph combine None Religious, graphregion(color(white))

*Table A1 – Slope Coefficients and R2 for how Beliefs about Republican Evangelical Proportions are Linked to Beliefs about Democratic None Proportions Across the Three Surveys
reg q42_4 q43_2 if none==1
reg q42_4 q43_2 if none==0 
	

*Figure A2 - Beliefs of the Percent of Nones in the Democratic Party and Evangelicals in the Republican Party by Subgroups in (March 2016 Data)
sum q42_4 q43_2 // sample perception
sum q42_4 q43_2 if none==1 // nones
sum q42_4 q43_2 if none==1 & pid7<4 // dem nones
sum q42_4 q43_2 if none==1 & pid7>4 // rep nones
sum q42_4 q43_2 if evan==1 // evans
sum q42_4 q43_2 if evan==1 & pid7<4 // dem evans
sum q42_4 q43_2 if evan==1 & pid7>4 // rep evans
tab none if pid7<4 // sample proportion dem nones
tab evan if pid7>4 // sample proportion rep evans
	
*Table A3 - How Beliefs about the Religious Composition of the Parties are Linked to Partisanship – March 2016 Data
reg pid7 c.q42_4##i.none c.q43_4##i.none c.q43_2##i.evan c.q42_2##i.evan white age ed female attend 


*Figure A3 – Examining Effects of Beliefs in Non-Stereotypical Party Compositions on Partisanship (March 2016)
reg pid7 c.q42_4##i.none c.q43_4##i.none c.q43_2##i.evan c.q42_2##i.evan white age ed female attend 
margins, at(q42_4=(0(10)100) none=(0 1)) l(76)
marginsplot, graphregion(color(white)) xtitle("Democratic Non-Attenders") recastci(rspike) ciopt(lc(gs10)) ///
		plot1op(lc(black) mc(black) ms(O)) plot2op(lc(black) mc(black) ms(Sh)) ytitle("Partisanship") title("") name(dem_none, replace) ///
		addplot(hist q42_4, percent yaxis(2) yscale(ax(2) range(0 100) alt off) fc(gs12) legend(order(3 "Religious" 4 "Nones") region(color(white))))
margins, at(q43_4=(0(10)100) none=(0 1)) l(76)
marginsplot, graphregion(color(white)) xtitle("Republican Non-Attenders") recastci(rspike) ciopt(lc(gs10)) ///
		plot1op(lc(black) mc(black) ms(O)) plot2op(lc(black) mc(black) ms(Sh)) ytitle("Partisanship") title("")  name(rep_none, replace) ///
		addplot(hist q43_4, percent yaxis(2) yscale(ax(2) range(0 100) alt off) fc(gs12) legend(order(3 "Religious" 4 "Nones") region(color(white))))
margins, at(q42_2=(0(10)100) evan=(0 1)) l(76)
marginsplot, graphregion(color(white)) xtitle("Democratic Evangelicals") recastci(rspike) ciopt(lc(gs10)) ///
		plot1op(lc(black) mc(black) ms(O)) plot2op(lc(black) mc(black) ms(Sh)) ytitle("Partisanship") title("")  name(dem_evan, replace)  ///
		addplot(hist q42_2, percent yaxis(2) yscale(ax(2) range(0 100) alt off) fc(gs12) legend(order(3 "Other" 4 "Evangelicals") region(color(white))))
margins, at(q43_2=(0(10)100) evan=(0 1)) l(76)
marginsplot, graphregion(color(white)) xtitle("Republican Evangelicals") recastci(rspike) ciopt(lc(gs10)) ///
		plot1op(lc(black) mc(black) ms(O)) plot2op(lc(black) mc(black) ms(Sh)) ytitle("Partisanship") title("")  name(rep_evan, replace) ///
		addplot(hist q43_2, percent yaxis(2) yscale(ax(2) range(0 100) alt off) fc(gs12) legend(order(3 "Other" 4 "Evangelicals") region(color(white))))

graph combine dem_none rep_none dem_evan rep_evan, col(2) graphregion(color(white))

*Figure 3 – The Interactive Effects of Religious Group Membership and Perceptions of Party Composition on Partisanship (All Three Data Sources)
*Second column of results
reg pid7 c.q42_4##i.none c.q43_4##i.none c.q43_2##i.evan c.q42_2##i.evan white age ed female attend  
margins, at(q42_4=(0(10)100) none=(0 1)) l(76)
marginsplot, graphregion(color(white)) xtitle("Democratic Non-Attenders") recastci(rspike) ciopt(lc(gs10)) ///
		plot1op(lc(black) mc(black) ms(O)) plot2op(lc(black) mc(black) ms(Sh)) ytitle("Partisanship") title("March 2016") name(dem_none16, replace) ///
		addplot(hist q42_4, percent yaxis(2) yscale(ax(2) range(0 100) alt off) fc(gs12) legend(order(3 "Religious" 4 "Nones") region(color(white))))
margins, at(q43_2=(0(10)100) evan=(0 1)) l(76)
marginsplot, graphregion(color(white)) xtitle("Republican Evangelicals") recastci(rspike) ciopt(lc(gs10)) ///
		plot1op(lc(black) mc(black) ms(O)) plot2op(lc(black) mc(black) ms(Sh)) ytitle("Partisanship") title("March 2016")  name(rep_evan16, replace) ///
		addplot(hist q43_2, percent yaxis(2) yscale(ax(2) range(0 100) alt off) fc(gs12) legend(order(3 "Other" 4 "Evangelicals") region(color(white))))

graph combine dem_none16 rep_evan16, col(1) graphregion(color(white))


************************
*All recoding and analyses using the June 2017 data.
************************
use june2017.dta

*Recodes

*evangelicals and nones
gen rt_ep=0
replace rt_ep=1 if (den==1 | den==3) & ba==1 & white==1  //white born again Protestants or "other christian"

gen none=0
replace none=1 if (den==6 | den==7) // atheist, agnostic, none

*Partisanship
recode pid7 (1/3=0)(4=1)(5/7=2), gen(pid3) // 0=dem, 1=ind, 2=rep
recode pid3 (0=0)(2=1)(1=.a), gen(dr)
la def dr 0"Democrat" 1"Republican"
la val dr dr

*Feeling therm difference
gen drdiff=ft_rep-ft_dem

*Table A0 – Descriptive Statistics from the Three Samples
sum female white agef rt_ep none
tab ed pid3

*Table A1 – Slope Coefficients and R2 for how Beliefs about Republican Evangelical Proportions are Linked to Beliefs about Democratic None Proportions Across the Three Surveys
reg dem_none rep_evan if none==1
reg dem_none rep_evan if none==0


*Table A4 - How Beliefs about the Religious Composition of the Parties is Linked to Partisanship and Partisan Feelings – June 2017 Data
reg pid7 i.none##c.dem_none i.none##c.rep_evan i.rt_ep##c.dem_none i.rt_ep##c.rep_evan female white agef ed attend5
outreg2 using june2017_table_a4.doc, dec(2) 
reg drdiff i.none##c.dem_none i.none##c.rep_evan i.rt_ep##c.dem_none i.rt_ep##c.rep_evan female white agef ed attend5
outreg2 using june2017_table_a4.doc, dec(2) 


*Figure 3 – The Interactive Effects of Religious Group Membership and Perceptions of Party Composition on Partisanship (All Three Data Sources)
*Third column of results
reg pid7 i.none##c.dem_none i.none##c.rep_evan i.rt_ep##c.dem_none i.rt_ep##c.rep_evan female white agef ed attend5
margins, at(dem_none=(0(10)100) none=(0 1)) l(76)
marginsplot, graphregion(color(white)) xtitle("Democratic Non-Attenders") recastci(rspike) ciopt(lc(gs10)) ///
		plot1op(lc(black) mc(black) ms(O)) plot2op(lc(black) mc(black) ms(Sh)) ytitle("Partisanship") ///
		addplot(hist dem_none, percent yaxis(2) yscale(ax(2) range(0 100) alt off) fc(gs12) legend(order(3 "Religious" 4 "Nones") region(color(white)))) ///
		title("June 2017") name(dem_nonep17, replace)
margins, at(rep_evan=(0(10)100) rt_ep=(0 1)) l(76)
marginsplot, graphregion(color(white)) xtitle("Republican Evangelicals") recastci(rspike) ciopt(lc(gs10)) ///
		plot1op(lc(black) mc(black) ms(O)) plot2op(lc(black) mc(black) ms(Sh)) ytitle("Partisanship") ///
		addplot(hist rep_evan, percent yaxis(2) yscale(ax(2) range(0 100) alt off) fc(gs12) legend(order(3 "Other" 4 "Evangelicals") region(color(white)))) ///
		title("June 2017")  name(rep_evanp17, replace)

graph combine dem_nonep rep_evanp, col(2) graphregion(color(white))

	*This puts all figure 3 panes together.
graph combine dem_nonep15 dem_none16 dem_nonep17 rep_evanp15 rep_evan16 rep_evanp17, col(3) graphregion(color(white))

*Figure 4 – The Interactive Effects of Religious Group Membership and Perceptions of Party Composition on Partisan Feelings (November 2015 and June 2017)
*Second column of results
reg drdiff i.none##c.dem_none i.none##c.rep_evan i.rt_ep##c.dem_none i.rt_ep##c.rep_evan female white agef ed attend5
margins, at(dem_none=(0(10)100) none=(0 1)) l(76)
marginsplot, graphregion(color(white)) xtitle("Democratic Non-Attenders") recastci(rspike) ciopt(lc(gs10)) ///
		plot1op(lc(black) mc(black) ms(O)) plot2op(lc(black) mc(black) ms(Sh)) ytitle("Republican-Democratic FT") ///
		addplot(hist dem_none, percent yaxis(2) yscale(ax(2) range(0 100) alt off) fc(gs12) legend(order(3 "Religious" 4 "Nones") region(color(white)))) ///
		title("June 2017") name(dem_none17, replace)
margins, at(rep_evan=(0(10)100) rt_ep=(0 1)) l(76)
marginsplot, graphregion(color(white)) xtitle("Republican Evangelicals") recastci(rspike) ciopt(lc(gs10)) ///
		plot1op(lc(black) mc(black) ms(O)) plot2op(lc(black) mc(black) ms(Sh)) ytitle("Republican-Democratic FT") ///
		addplot(hist rep_evan, percent yaxis(2) yscale(ax(2) range(0 100) alt off) fc(gs12) legend(order(3 "Other" 4 "Evangelicals") region(color(white)))) ///
		title("June 2017")  name(rep_evan17, replace)
graph combine dem_none17 rep_evan17, col(2) graphregion(color(white))

*This puts together all four frames of Figure 4.
graph combine dem_none15 dem_none17 rep_evan15 rep_evan17, col(2) graphregion(color(white))


*Figure 5 – Does Priming Partisan Identification Affect Religious Composition Beliefs? (June 2017)
reg dem_none i.dr##i.t_party##i.none agef female white ed
margins, dydx(t_party) at(dr=(0 1) none=(1)) l(90)
marginsplot, yline(0, lc(red) lp(dash)) xtitle("") ytitle("Marginal Effect of Partisan Priming", si(medsmall)) ///
	title("Democrats Who Are Nones (by Nones)", si(medium)) name(dem_none, replace) ///
	graphregion(color(white)) xscale(range(-.25 1.25)) ciopt(lc(black)) plotop(mc(black)) recast(scatter)

reg rep_evan i.dr##i.t_party##i.rt_ep agef female white ed
margins, dydx(t_party) at(dr=(0 1) rt_ep=(1)) l(90)
marginsplot, yline(0, lc(red) lp(dash)) xtitle("") ytitle("") ///
	title("Republicans Who Are Evangelical (by Evangelicals)") name(rep_evan, replace) ///
	graphregion(color(white)) xscale(range(-.25 1.25)) ciopt(lc(black)) plotop(mc(black)) recast(scatter)

reg dem_none i.dr##i.t_party##i.none agef female white ed
margins, dydx(t_party) at(dr=(0 1) none=(0)) l(90)
marginsplot, yline(0, lc(red) lp(dash)) xtitle("") ytitle("Marginal Effect of Partisan Priming", size(medsmall)) ///
	title("Democrats Who Are Nones(by the Religious)", si(medium)) name(dem_rel, replace) ///
	graphregion(color(white)) xscale(range(-.25 1.25)) ciopt(lc(black)) plotop(mc(black)) recast(scatter)

reg rep_evan i.dr##i.t_party##i.rt_ep agef female white ed
margins, dydx(t_party) at(dr=(0 1) rt_ep=(0)) l(90)
marginsplot, yline(0, lc(red) lp(dash)) xtitle("") ytitle("") ///
	title("Republicans Who Are Evangelical (by non-Evangelicals)") name(rep_notevan, replace) ///
	graphregion(color(white)) xscale(range(-.25 1.25)) ciopt(lc(black)) plotop(mc(black)) recast(scatter)

graph combine dem_none rep_evan dem_rel rep_notevan, graphregion(color(white)) xsize(8) ysize(8)


*Figure 6 – Does Priming Religious Composition Beliefs Affect Partisan Identification and Strength? (June 2017)
*Estimates are from these models. t_comp is 0=partisanship asked first, 1=religious composition questions asked first.
reg pid7 t_comp agef female white ed none rt_ep, l(90)
reg pid7 t_comp agef female white ed if none==1, l(90)
reg pid7 t_comp agef female white ed if rt_ep==1, l(90)

reg pidst t_comp agef female white ed none rt_ep, l(90)
reg pidst t_comp agef female white ed if none==1, l(90)
reg pidst t_comp agef female white ed if rt_ep==1, l(90)



